package com.halixun.d2app.adapter.holder;

import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.halixun.d2app.R;
import com.halixun.d2app.adapter.MyOrderListAdapter;
import com.halixun.d2app.base.BaseViewHolder;
import com.halixun.d2app.bean.OrderListInfo;
import com.halixun.d2app.utils.DataOperationUtil;

/**
 * @ProjectName: D2App
 * @Package: com.halixun.d2app.adapter.holder
 * @ClassName: MyOrderListViewHolder
 * @Description: java类作用描述
 * @Author: hdx
 * @CreateDate: 2019/11/28 19:20
 * @UpdateUser: hdx
 * @UpdateDate: 2019/11/28 19:20
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class MyOrderListViewHolder extends BaseViewHolder<OrderListInfo> {

    private TextView lowly, name, num, price;

    private ViewGroup rootView;

    private View line;

    private MyOrderListAdapter.MyOrderListAdapterListener listAdapterListener;

    public MyOrderListViewHolder(View itemView) {
        super(itemView);
        initView();
        setListener();
    }

    public MyOrderListViewHolder(View itemView, MyOrderListAdapter.MyOrderListAdapterListener listAdapterListener) {
        this(itemView);
        this.listAdapterListener = listAdapterListener;
    }

    private void setListener() {
        itemView.setOnClickListener(v -> {
            if (null != listAdapterListener) {
                listAdapterListener.onOrderListClickListener(getAdapterPosition());
            }
        });
    }

    private void initView() {
        lowly = itemView.findViewById(R.id.lowly);
        name = itemView.findViewById(R.id.name);
        num = itemView.findViewById(R.id.num);
        price = itemView.findViewById(R.id.price);
        rootView = itemView.findViewById(R.id.rootView);
        line = itemView.findViewById(R.id.line);
    }

    @Override
    public void setLayoutInfo(OrderListInfo info) {
        lowly.setText((getLayoutPosition() + 1) + "");
        name.setText(info.getTitle());
        num.setText(info.getCommodityNumber() + "");
        price.setText("￥" + DataOperationUtil.mul(info.getPrice()
                , info.getCommodityNumber()));
        rootView.setBackgroundColor(Color.parseColor(info.isSelected()?"#FFD39A":"#FFFFFF"));
        line.setVisibility(info.isSelected()?View.INVISIBLE:View.VISIBLE);
    }

    @Override
    public void setLayoutInfo(OrderListInfo info, int tag) {
        super.setLayoutInfo(info, tag);
        rootView.setBackgroundColor(Color.parseColor(info.isSelected()?"#FFD39A":"#FFFFFF"));
        line.setVisibility(info.isSelected()?View.INVISIBLE:View.VISIBLE);
    }
}
